﻿using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Loki.Utils
{
    public class BinarySettingsSerializer : ISettingsSerializer
    {
        private BinaryFormatter _Formatter = new BinaryFormatter();

        public byte[] Serialize(object P_Obj)
        {
            using (MemoryStream L_Stream = new MemoryStream())
            {
                _Formatter.Serialize(L_Stream, P_Obj);
                return L_Stream.GetBuffer();
            }
        }

        public object Deserialize(byte[] P_Bytes)
        {
            using (MemoryStream L_Stream = new MemoryStream(P_Bytes))
            {
                return _Formatter.Deserialize(L_Stream);
            }
        }
    }
}
